﻿CREATE PROCEDURE [acms].[Post_GetBySiteUrlPostUrlAndVersionTimeStamp]
	@SiteUrl varchar(50), 
	@PostUrl varchar(255),
	@VersionTimeStamp datetime
AS
	declare @SiteId int
	select @SiteId = Id From Site_View where Root = @SiteUrl
	
	if(@SiteId is null)
		select @SiteId = SiteId From SiteMappings where MappingName = @SiteUrl
	
	SELECT *
	From Post_View
	Where
		SiteId = @SiteId
		and isNull(ParentPath, '') + Name = @PostUrl
		and 
		(
			(StartDate <= @VersionTimeStamp and isNull(EndDate, DateAdd(m, 1, @VersionTimeStamp)) > @VersionTimeStamp)
			or
			(StartDate is null and EndDate is null and @VersionTimeStamp is null)
		)
		

RETURN 0;